import { cloneDeep } from 'lodash-es'
import { addCommonPointLayer, layerMap, removeLayerAndSource, showMapPop } from '.'
import TestMapPop from '@/views/MajorGuarantee/components/map-pop/TestMapPop.vue'

// 添加测试点位图层
export const addTestGroupOnePointLayer = async (show: boolean) => {
    const layerId = layerMap.testLayer

    if (show) {
        // 先移除老图层
        removeLayerAndSource(layerId)
        // 数据资源
        const geojson = {
            type: 'FeatureCollection',
            features: [
                {
                    type: 'Feature',
                    geometry: {
                        type: 'Point',
                        coordinates: [119.29387527, 30.281776],
                    },
                    properties: {
                        name: '模拟站点1',
                    },
                },
            ],
        }
        // 添加点位图层
        addCommonPointLayer({
            layerId,
            geojson,
            onClick: (e: any) => {
                showMapPop({
                    VueComponent: TestMapPop,
                    properties: cloneDeep(e.features[0].properties),
                    coordinates: cloneDeep(e.features[0].geometry.coordinates),
                })
            },
        })
    } else {
        removeLayerAndSource(layerId)
    }
}
